package com.weipeep.sys.listener;

import com.weipeep.common.utils.DateUtils;
import com.weipeep.sys.dao.MottoDao;
import com.weipeep.sys.domain.MottoDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class ConsumerListener {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private MottoDao mottoDao;
    @KafkaListener(topics = "test-topic")
    public void onMessage(String msg){
        //insertIntoDb(buffer);//这里为插入数据库代码
        MottoDO mottoDO = new MottoDO();
        mottoDO.setType(1);
        mottoDO.setMotto(msg+"_"+DateUtils.format(DateUtils.now(),DateUtils.DATE_TIME_PATTERN_14));
        mottoDO.setName(msg);
        int count = mottoDao.insert(mottoDO);
        logger.info("接受消息:{}---",msg);
    }
}